#!/bin/sh
#|-*- mode:lisp -*-|#
#|
exec ros -Q -- $0 "$@"
|#

(progn ;;init forms
  (ros:ensure-asdf)
  (ql:quickload '(:lilu-desk/full
                  :lilu-swank
                  :lilu-swank-client/server
                  :lilu-roswell)
                :silent t))

(defpackage :ros.script.lilu-server.3766064847
  (:use :cl))
(in-package :ros.script.lilu-server.3766064847)

(opts:define-opts
  #.lilu-roswell:*default-help-option*
  #.(lilu-roswell:merge-options
     lilu-roswell:*default-swank-port-option*
     '(:default lilu-swank:*default-swank-port*))
  (:name :interface
   :description "the swank interface"
   :required nil
   :default lilu-swank:*default-swank-interface*
   :short #\i
   :long "inter"
   :arg-parser #'identity
   :meta-var "INTER")
  (:name :style
   :description "the swank style (STYLE must be spawm/sigio/fd-handler/default/nil)"
   :required nil
   :default nil
   :short #\s
   :long "style"
   :arg-parser (lilu-roswell:options-make-enum-parser
                `("spawn" :spawn "sigio" :sigio "fd-handler" :fd-handler
                          "nil" nil "default" ,swank:*communication-style*))
   :meta-var "STYLE")
  (:name :log-event-p
   :description "enable to log events"
   :required nil
   :default nil
   :short #\l
   :long "log"
   :arg-parser (lilu-roswell:options-make-enum-parser '("y" t "n" nil "yes" t "no" nil))
   :meta-var "y/n")
  #.lilu-roswell:*default-debugger-option*
)

(defun main (&rest argv)
  (declare (ignorable argv))
  (lilu-roswell:init)
  (multiple-value-bind (options free-args)
      (lilu-roswell:parse-options argv :free-args-p nil)
    (declare (ignore free-args))
    (let ((debugger (lilu-roswell:options-get-value options :debugger)))
      (lilu-debugger:with-debugger (debugger)
        (lilu-roswell:options-check-for-help options
                                             :prefix "create a swank server"
                                             :suffix "so that's how it works…"
                                             :usage-of "lilu-swank-server.ros"
                                             :args     "")
        (let ((args (append
                     (lilu-roswell:options-get-keys options
                                                    :port
                                                    :interface
                                                    :style
                                                    :log-event-p)
                     (list :wait-p t :dont-close-p t))))
          (apply #'lilu-swank:create-swank-server args))))))

;;; vim: set ft=lisp lisp:
